<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Products</title>
    </h:head>
    <f:view beforePhase="#{UserDisplayManagedBean.doDisplay}">
        <f:view beforePhase="#{ProductManagedBean.initView}">
            <h:body>
                <h:form prependId="false">
                    <p:growl id="notif" showDetail="true"/>  
                    <p:poll interval="5"   
                            actionListener="#{MessageManagedBean.checkNewMessage}" immediate="true" update="notif" />
                    <p:growl id="growl" showDetail="true" />  
                    <div id="top" class="top">
                        <h:graphicImage value="/image/newHeader.jpg"/>
                    </div>
                    <div id="content">

                        <table >
                            <tr><td>
                                    <p:toolbar style="background-color:darkred;font-size:70%;height:25px;width:100%"> 
                                        <p:toolbarGroup align="right">
                                            <p:button title="Home" image="ui-icon-home" outcome ="InventoryDeptWorkspace"/>                                  
                                            <p:button title="Notes" image="ui-icon-note" outcome="tasks"/>                                    
                                            <p:button title="Mail" outcome="messages" image="ui-icon-mail-closed"/>                                   
                                            <p:button title="Edit Preferences" image="ui-icon-gear"/>                                   
                                            <p:button title="Help" image="ui-icon-help"/>
                                            <p:commandButton title="Log Out" immediate="true" type="submit" image="ui-icon-close" actionListener="#{UserManagedBean.doLogout}"/> 
                                        </p:toolbarGroup>
                                    </p:toolbar></td>
                                <td>
                                    <h:graphicImage value="boxes.png" style="width:35px;height:35px" />
                                    <h:outputText value="         "/>
                                    <h:outputText value="Products" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                    <p:spacer width="100" height="10"/>
                                </td>
                            </tr>
                            <tr>

                                <td style="vertical-align:top">
                                    <p:menu style="width:200px;font-size: 12px;font-family: Tahoma;border-style: ridge">  
                                        <p:submenu label="Inventories" > 
                                            <p:menuitem value="New Product" url="http://localhost:8080/MerlionERP-war/SCM/addProduct.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>  
                                            <p:menuitem value="View All Products" url="http://localhost:8080/MerlionERP-war/SCM/products.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>  
                                            <p:menuitem value="New Material" url="http://localhost:8080/MerlionERP-war/SCM/addMaterial.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>                                      
                                            <p:menuitem value="View All Materials" url="http://localhost:8080/MerlionERP-war/SCM/materials.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                            <p:menuitem value="View Unhoused Inventories" url="http://localhost:8080/MerlionERP-war/SCM/unhousedInventories.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                            <p:menuitem value="View Inventory Movements" url="http://localhost:8080/MerlionERP-war/SCM/inventoryMovements.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />

                                        </p:submenu>
                                        <p:submenu label="Warehouses" >
                                            <p:menuitem value="New Warehouse" url="http://localhost:8080/MerlionERP-war/SCM/addWarehouse.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>        
                                            <p:menuitem value= "View All Warehouses" url="http://localhost:8080/MerlionERP-war/SCM/warehouses.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                        </p:submenu>
                                        <p:submenu label="Shipments and Orders">
                                            <p:menuitem value="Delivery Orders" url="http://localhost:8080/MerlionERP-war/SCM/deliveryOrders.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>
                                            <p:menuitem value="Picking Orders" url="http://localhost:8080/MerlionERP-war/SCM/pickingOrders.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>            
                                        </p:submenu>
                                    </p:menu>
                                    <p:calendar mode="inline" style="font-size:11px;font-family:Tahoma"/>
                                </td>

                                <td style="vertical-align:top">

                                    <p:toolbar style="background-color:  #d9bb73;font-size: 70%;width:99.5%"> 
                                        <p:toolbarGroup align="left">  
                                            <p:button value="New Product" outcome="addProduct" image="ui-icon-plus"/>
                                            <p:commandButton value="Delete" title="Delete" image="ui-icon ui-icon-trash" oncomplete="deleteDialog.show()"/>                                   

                                        </p:toolbarGroup>  
                                    </p:toolbar> 

                                    <p:dataTable id="panel" 
                                                 var="products" value="#{ProductManagedBean.productList}"                       
                                                 paginator="true" rows="5"  
                                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                                 rowEditListener="#{ProductManagedBean.onRowEditProduct}"
                                                 rowsPerPageTemplate="5,10,15"  style="font-size:60%;width:100%"
                                                 selection="#{ProductManagedBean.selectedProducts}"
                                                 emptyMessage="No data found with given criteria" widgetVar="productTable">  

                                        <f:facet name="header">                           
                                            <p:outputPanel style="text-align:right"  >
                                                <h:outputText value="Search all fields:" style="margin-left:840px" />  
                                                <p:inputText id="globalFilter" onkeyup="productTable.filter()" style="right:-100px;width:150px" />  
                                            </p:outputPanel>
                                        </f:facet> 

                                        <p:column selectionMode="multiple"/> 
                                        <!--style="border-left-color:transparent;border-right-color:transparent"/>-->

                                        <p:column headerText="View" style="width:16px;border-right-color:transparent" >  
                                            <p:rowToggler />  
                                        </p:column> 

                                        <p:column headerText="Edit" style="width:20px;border-left-color:transparent;border-right-color:transparent">    
                                            <p:rowEditor/>
                                        </p:column>


                                        <p:column headerText="Del." style="width: 16px;border-left-color:transparent">  
                                            <!--DELETE-->
                                            <p:commandButton title="Delete" image="ui-icon ui-icon-trash" ajax="true" immediate="true"
                                                             update="panel" oncomplete="productDialog.show()">
                                                <f:setPropertyActionListener target="#{ProductManagedBean.selectedProduct}"
                                                                             value="#{products}"/>
                                            </p:commandButton>
                                        </p:column>


                                        <!--Product ID-->
                                        <p:column sortBy="#{products.itemId}" filterBy="#{products.itemId}" filterMatchMode="contains"
                                                  filterStyle="width:50px">
                                            <!--style="border-left-color:transparent;border-right-color:transparent">-->
                                            <f:facet name="header">
                                                <h:outputText value="ID"/>
                                            </f:facet>
                                            <h:outputText value="#{products.itemId}"/>
                                        </p:column>

                                        <!--Product Name-->
                                        <p:column headerText="Product Name" sortBy="#{products.name}" filterBy="#{products.name}" 
                                                  filterMatchMode="contains"
                                                  filterStyle="width:150px">
                                            <!--style="border-left-color:transparent;border-right-color:transparent">-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{products.name}" />  
                                                </f:facet>  
                                                <f:facet name="input">
                                                    <p:inputText value="#{products.name}" style="width:100%"/>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>   

                                        <!--Description-->
                                        <p:column headerText="Description" sortBy="#{products.description}" 
                                                  filterBy="#{products.description}" filterMatchMode="contains"
                                                  filterStyle="width:250px">
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{products.description}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{products.description}" style="width:100%" />
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  


                                        <!--In hand Quantity-->
                                        <p:column headerText="In Hand Quantity" sortBy="#{products.inHandQty}" 
                                                  filterBy="#{products.inHandQty}" filterMatchMode="contains">
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  

                                            <h:outputText value="#{products.inHandQty}" />  

                                        </p:column>  

                                        <!--Reserved Quantity-->
                                        <p:column headerText="Reserved Quantity" sortBy="#{products.reservedQty}" 
                                                  filterBy="#{products.reservedQty}" filterMatchMode="contains">
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  

                                            <h:outputText value="#{products.reservedQty}" />  

                                        </p:column>


                                        <p:column style="width:32px">  
                                            <p:commandLink update="display1" oncomplete="editDialog.show()" title="Edit Details">  
                                                <p:graphicImage value="clipboard.png" style="width:20px;height:20px"/>
                                                <f:setPropertyActionListener value="#{products}" target="#{ProductManagedBean.selectedViewProduct}" />  
                                                <f:setPropertyActionListener value="#{true}" target="#{ProductManagedBean.editMode}" />  
                                            </p:commandLink>                                                                
                                        </p:column>

                                        <p:rowExpansion>  
                                            <h:panelGrid id="display" columns="6" cellpadding="3"
                                                         style="font-family:Tahoma; font-size:10px;border-color:transparent;column-rule-style:hidden">

                                                <h:outputText value="Product Id" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.itemId}" />

                                                <h:outputText value="Product Name" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.name}" />  

                                                <h:outputText value="Description" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.description}" />  

                                                <h:outputText value="Shelf Life" />
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.shelfLife}" /> 

                                                <h:outputText value="Case Weight" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.caseWeight}" />

                                                <h:outputText value="Base Price" />
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.basePrice}" />

                                                <h:outputText value="Limit Price" />
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.limitPrice}" />

                                                <h:outputText value="List Price" />
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.listPrice}" />

                                                <h:outputText value="Production Rate" />
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.productionRate}" />

                                                <h:outputText value="In Hand Quantity" />
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.inHandQty}" />

                                                <h:outputText value="Reserved Quantity"/>
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{products.reservedQty}" />

                                            </h:panelGrid>  
                                        </p:rowExpansion>

                                    </p:dataTable>  


                                    <!--DIALOG FOR DELETING A  SINGLE ROW-->
                                    <p:confirmDialog message="Are you sure you want to delete this product?"  
                                                     showEffect="blind" hideEffect="blind" modal="true" 
                                                     header="Delete Product" severity="alert" widgetVar="productDialog">  
                                        <center>
                                            <p:commandButton value="Yes" update="panel" ajax="true" immediate="true" oncomplete="productDialog.hide()"  
                                                             actionListener="#{ProductManagedBean.deleteProduct}" />  
                                            <p:commandButton value="No" onclick="productDialog.hide()" type="button" />   
                                        </center>

                                    </p:confirmDialog>  


                                    <p:ajaxStatus style="width:16px;height:16px;">  
                                        <f:facet name="start">  
                                            <h:graphicImage value="25(2).gif" />  
                                        </f:facet>  

                                        <f:facet name="complete">  
                                            <h:outputText value="" />  
                                        </f:facet>  
                                    </p:ajaxStatus>
                                </td>
                            </tr>

                            <tr></tr>
                        </table>

                        <p:dialog header="Product Detail" widgetVar="editDialog" resizable="false"  
                                  width="800" showEffect="blind" hideEffect="blind">  
                            <center>
                                <h:panelGrid id="display1" columns="3" cellpadding="4" style="font-family:Tahoma; font-size:12px">  


                                    <h:outputText value="Product Id" />  
                                    <h:outputText value=":"/>
                                    <h:outputText value="#{ProductManagedBean.selectedViewProduct.itemId}" />  

                                    <h:outputText value="Product Name" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.name}" style="font-weight:bold" rendered="#{!ProductManagedBean.editMode}"/>  
                                        <p:inputText value="#{ProductManagedBean.selectedViewProduct.name}" rendered="#{ProductManagedBean.editMode}" label="Product Name"/>  
                                    </h:panelGroup> 

                                    <h:outputText value="Description" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.description}" style="font-weight:bold" rendered="#{!ProductManagedBean.editMode}"/>  
                                        <p:inputText value="#{ProductManagedBean.selectedViewProduct.description}" rendered="#{ProductManagedBean.editMode}" label="Description"/>                            
                                    </h:panelGroup>  

                                    <h:outputText value="Shelf Life"/> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.shelfLife}" style="font-weight:bold" rendered="#{!ProductManagedBean.editMode}"/>  
                                        <p:inputText value="#{ProductManagedBean.selectedViewProduct.shelfLife}" rendered="#{ProductManagedBean.editMode}" label="Shelf Life"/>  
                                    </h:panelGroup>  

                                    <h:outputText value="Case Weight" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.caseWeight}" style="font-weight:bold" rendered="#{!ProductManagedBean.editMode}"/>  
                                        <p:inputText value="#{ProductManagedBean.selectedViewProduct.caseWeight}" rendered="#{ProductManagedBean.editMode}" label="Case Weight"/>  
                                    </h:panelGroup> 

                                    <h:outputText value="Base Price" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.basePrice}" style="font-weight:bold" rendered="#{!ProductManagedBean.editMode}"/>  
                                        <p:inputText value="#{ProductManagedBean.selectedViewProduct.basePrice}" rendered="#{ProductManagedBean.editMode}" required="true" label="Last Name"/>  
                                    </h:panelGroup>

                                    <h:outputText value="Limit Price" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.limitPrice}" style="font-weight:bold" rendered="#{!ProductManagedBean.editMode}"/>  
                                        <p:inputText value="#{ProductManagedBean.selectedViewProduct.limitPrice}" rendered="#{ProductManagedBean.editMode}" required="true" label="Last Name"/>  
                                    </h:panelGroup> 

                                    <h:outputText value="List Price" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.listPrice}" style="font-weight:bold" rendered="#{!ProductManagedBean.editMode}"/>  
                                        <p:inputText value="#{ProductManagedBean.selectedViewProduct.listPrice}" rendered="#{ProductManagedBean.editMode}" required="true" label="Last Name"/>  
                                    </h:panelGroup> 

                                    <h:outputText value="In Hand Quantity" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.inHandQty}" style="font-weight:bold"/>  

                                    </h:panelGroup> 

                                    <h:outputText value="Reserved Quantity" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{ProductManagedBean.selectedViewProduct.reservedQty}" style="font-weight:bold"/>  

                                    </h:panelGroup> 

                                    <h:outputText value=""/>
                                    <h:outputText value=""/>
                                    <h:outputText value=""/>
                                    <h:outputText value=""/>
                                    <h:outputText value=""/>
                                    <h:outputText value=""/>

                                    <h:outputText value=""/>
                                    <h:outputText value=""/>

                                    <p:outputPanel rendered="#{ProductManagedBean.editMode}" layout="block" style="text-align:right">  
                                        <p:commandButton value="Save" update="panel" actionListener="#{ProductManagedBean.editProduct}"   
                                                         oncomplete="editDialog.hide()" image="ui-icon ui-icon-check" />  
                                        <p:commandButton value="Cancel" onclick="editDialog.hide()" type="button" image="ui-icon ui-icon-close"/>  
                                    </p:outputPanel>  


                                </h:panelGrid>  
                            </center>
                        </p:dialog>  


                        <!--DIALOG FOR DELETING MULTIPLE ROW OF CUSTOMER-->
                        <p:dialog header="Delete Selected Records" modal="true" widgetVar="deleteDialog">

                            <h:outputText value="You are about to permanently delete records." /><br /><br />
                            <h:outputText value="Are you sure you want to continue?" /><br /><br/>

                            <center>
                                <p:commandButton value="Yes" ajax="true" immediate="true" update="panel" 
                                                 oncomplete="deleteDialog.hide()" actionListener="#{ProductManagedBean.deleteProducts}" />
                                <p:commandButton value="No" oncomplete="deleteDialog.hide()" /> 

                            </center>
                        </p:dialog>


                    </div>

                    <div id="bottom" class="bottom">
                        <h:graphicImage value="/image/merlionfooter.jpg"/>
                    </div>
                </h:form>
            </h:body>
        </f:view>
    </f:view>
</html>